//
//  VideoTableViewCell.m
//  Delicious2
//
//  Created by FSD on 16/1/7.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "VideoTableViewCell.h"

@implementation VideoTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

#pragma mark - 创建视图
- (void)createView {
    self.videoImage = [[UIImageView alloc] initWithFrame:CGRectZero];
    self.videoTitle = [[UILabel alloc] initWithFrame:CGRectZero];
    self.videoTitle.textColor = [UIColor whiteColor];
    self.videoTitle.textAlignment = NSTextAlignmentCenter;
    self.videoTitle.font = [UIFont systemFontOfSize:18];
    self.videoTitle.highlighted = YES;
    self.videoTitle.highlightedTextColor = [UIColor whiteColor];
    self.titleDetail = [[UILabel alloc] initWithFrame:CGRectZero];
    self.titleDetail.textColor = [UIColor whiteColor];
    self.titleDetail.textAlignment = NSTextAlignmentCenter;
    self.titleDetail.font = [UIFont systemFontOfSize:14];
    self.titleDetail.highlighted = YES;
    self.titleDetail.highlightedTextColor = [UIColor whiteColor];
    self.videoMode = [[UILabel alloc] initWithFrame:CGRectZero];
    self.videoMode.textColor = [UIColor whiteColor];
    self.videoMode.layer.cornerRadius = 3;
    self.videoMode.clipsToBounds = YES;
//    self.videoMode.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:69 / 255.0 blue:0 / 255.0 alpha:1.0];
    self.videoMode.backgroundColor = [UIColor clearColor];
    self.videoMode.numberOfLines = 2;
    self.videoMode.font = [UIFont boldSystemFontOfSize:18.0f];
    self.videoMode.textAlignment = NSTextAlignmentCenter;
    self.titleImage = [[UIImageView alloc] initWithFrame:CGRectZero];

    [self.contentView addSubview:self.videoImage];
    [self.videoImage addSubview:self.titleImage];
    [self.videoImage addSubview:self.videoTitle];
    [self.videoImage addSubview:self.titleDetail];
    [self.titleImage addSubview:self.videoMode];
}

- (void)setDataModel:(DataModel *)dataModel {
    
    //将dataModel指向同一片空间
    if (_dataModel != dataModel) {
        _dataModel = dataModel;
    }
    [self.videoImage sd_setImageWithURL:[NSURL URLWithString:dataModel.image] placeholderImage:[UIImage imageNamed:@"ImagePlace"]];
    
    NSArray *nameArray = [dataModel.series_name componentsSeparatedByString:@"#"];
//    NSLog(@"%@", nameArray);
    self.videoTitle.text = nameArray[2];
    
    NSString *episodeStr = [NSString stringWithFormat:@"%@/%@集", dataModel.episode, dataModel.episode_sum];
    NSString *numStr = [NSString stringWithFormat:@"%@人做过", dataModel.play];
    NSString *detailStr = [NSString stringWithFormat:@"%@ %@ %@", nameArray[1], episodeStr, numStr];
    self.titleDetail.text = detailStr;
    
    self.titleImage.image = [UIImage imageNamed:@"VideoLabel"];
    self.videoMode.text = dataModel.tag;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.videoImage.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    self.videoTitle.frame = CGRectMake(self.frame.size.width / 4, self.frame.size.height / 3, self.frame.size.width / 2, self.frame.size.height / 8);
    self.titleDetail.frame = CGRectMake(self.frame.size.width / 6, self.videoTitle.frame.origin.y + self.videoTitle.frame.size.height, self.frame.size.width / 3 * 2, self.frame.size.height / 8);
    self.titleImage.frame = CGRectMake(- 5, 5, self.frame.size.width / 5 + self.frame.size.width / 60, self.frame.size.height / 3);
    self.videoMode.frame = CGRectMake(self.titleImage.frame.origin.x + self.titleImage.frame.size.width / 39 * 14, -15, self.titleImage.frame.size.width / 8 * 3, self.titleImage.frame.size.height);
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
